package com.erp.erp_servers.Role.imp;

import com.erp.erp_dao.Role.IRoleDAO;
import com.erp.erp_entitys.Role.RoleEntity;
import com.erp.erp_entitys.Role.RoleExample;
import com.erp.erp_servers.Role.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ImpRoleService
 * @Description TODO
 * @Author songjizhen
 * @Date 2020-07-04 10:08
 * @Version 1.0
 */
@Service
public class ImpRoleService implements IRoleService {
    @Autowired
    IRoleDAO roleDAO;
    /**
     * 根据主键删除角色
     *
     * @param id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return roleDAO.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteByExample(RoleExample example) {
        return roleDAO.deleteByExample(example);
    }

    /**
     * 新增角色
     *
     * @param record
     * @return
     */
    @Override
    public int insertSelective(RoleEntity record) {
        return roleDAO.insertSelective(record);
    }

    /**
     * 根据条件查询角色
     *
     * @param record
     * @return
     */
    @Override
    public List<RoleEntity> selectByExample(RoleEntity record) {
        RoleExample example=new RoleExample();
        RoleExample.Criteria criteria = example.createCriteria();
        if(record.getId() !=null){
            criteria.andIdEqualTo(record.getId());
        }
        if(record.getCode() !=null && record.getCode() !=""){
            criteria.andCodeLike("%"+record.getCode()+"%");
        }
        if(record.getName() !=null && record.getName() !=""){
            criteria.andNameLike("%"+record.getName()+"%");
        }
        if(record.getType() !=null ){
            criteria.andTypeEqualTo(record.getType());
        }
        List<RoleEntity> roleEntities = roleDAO.selectByExample(example);
        return roleEntities;
    }

    @Override
    public List<RoleEntity> selectByExample(RoleExample example) {
        return roleDAO.selectByExample(example);
    }

    /**
     * 根据主键更新角色
     *
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(RoleEntity record) {
        return roleDAO.updateByPrimaryKeySelective(record);
    }
}
